#ifndef SKETCH_H
#define SKETCH_H

#ifdef _WIN32
	#include <windows.h>
	#include <GL/gl.h>
	#include <GL/glu.h>
	#include "GLUT/glut.h"
#else
	#include <OpenGL/gl.h>
	#include <OpenGL/glu.h>
	#include <GLUT/glut.h>
#endif

#include <vector>
#include "Geometry.h"
#include "GeometryFunctions.h"

using namespace std;

#ifndef RENDER_DEF
#define RENDER_DEF
typedef enum {RAW_POINTS, CONTROL_POINTS, POLYLINE, CATMULL_ROM} RenderModeType;
#endif

///////////////////////////////////////
// class CSketch                     //
// Last updated: 3rd Aug 2012        //
// Contains a single sketched curve  //
///////////////////////////////////////
class CSketch
{
public:
	CSketch(void);
	CSketch(int numPixels, int pixel[][2], GLuint startTime, GLuint sketchTime, int area_width, int area_height);
	CSketch(CSketch* sketch); // Copies control points for use in modelling
	virtual ~CSketch(void);

	GLuint startTime;	// time stamp - can be used to group sketches
	GLuint sketchTime;	// time to draw sketch - can be used to classify sketch (e.g. scribbles are done quickly)

	int max_height;
	int min_height;
	bool closed;

	void display2D(RenderModeType renderMode);
	bool isClosed();

	vector<CVec2di*>* getRawControlPoints()  { return &rawControlPoints;  }
	vector<CVec2df*>* getUnitControlPoints() { return &unitControlPoints; }
	
private:

	vector<CVec2di *> sketchPixels;      // raw data (mouse event coordinates)
	vector<CVec2di *> rawControlPoints;  // sampling of mouse data
	vector<CVec2df *> unitControlPoints; // control points normalised to the unit vector

	// Used for normalisation of the sketch points
	int sketch_area_width;  // Width  of the sketch area the sketch was drawn in
	int sketch_area_height; // Height of the sketch area the sketch was drawn in

	double	innerControlPointRatio;

	void	_drawCatmullRomSpline();
	void	computeInnerControlPointRatio();
	void	computeRawControlPoints();
	void	computeUnitControlPoints(); // Translates control points from the sketch window coordinates to unit vector coordinates

	template <typename T> void resamplePoints(vector<CVec2d<typename T>*>*input, vector<CVec2d<typename T>*>* output);
};

#endif
